# 基类算法
import numpy as np

from config import GlobalConfig


class DummyAlgorithmBase:
    def __init__(self, n_agent, n_thread, space, mcv=None, team=None):
        self.n_agent = n_agent
        self.n_thread = n_thread
        self.team = team
        self.ScenarioConfig = GlobalConfig.ScenarioConfig
        self.attack_order = {}
        self.team_agent_uid = GlobalConfig.ScenarioConfig.AGENT_ID_EACH_TEAM[team]

    def interact_with_env(self, State_Recall):
        """
            与环境交互
        @param State_Recall:
        @return:所有线程的动作
        """
        # print(time.time())
        assert State_Recall['Latest-Obs'] is not None, ('make sure obs is ok')
        ENV_PAUSE = State_Recall['ENV-PAUSE']
        ENV_ACTIVE = ~ENV_PAUSE

        assert self.n_thread == len(ENV_ACTIVE), ('the number of thread is wrong?')
        n_active_thread = sum(ENV_ACTIVE)

        # 初始化决策
        actions = np.zeros(shape=(self.n_thread, self.n_agent, 8))

        # 获取决策
        for thread in range(self.n_thread):
            if ENV_PAUSE[thread]:
                # 如果,该线程停止，不做任何处理
                continue
            actions[thread] = self.making_decision(
                state=State_Recall
                # thread=thread,
                # step_cnt=State_Recall['Current-Obs-Step'][thread],
                # Env_Suffered_Reset=State_Recall['Env-Suffered-Reset'][thread],
                # team_info=State_Recall['Latest-Team-Info'][0][0]['dataArr'],
            )

        actions[ENV_PAUSE] = np.nan

        actions = actions if GlobalConfig.mt_act_order == 'new_method' else np.swapaxes(actions, 0, 1)

        # 决策计数加一
        return actions, {}

    def making_decision(self, state):
        """
            进行决策
        @param kwargs:包含本次决策所需要的参数
        @return:act_each_agent
        """
        # 初始化智能体的动作
        act_each_agent = np.zeros(shape=(self.n_agent, 8))

        return act_each_agent